package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.RoleBean;
import com.project.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("role")
@Api(tags = "角色控制器")
public class RoleController {
    @Autowired
    private IRoleService roleService;
    @ApiOperation("分页查询角色信息")
    @ApiImplicitParam(name = "pageNO",value = "页码",required = true)
    @RequestMapping("cutByItem")
    @RequiresPermissions("role:*")
    public IPage<RoleBean> cutByItem(Integer pageNO) {
        return roleService.cutByItem(pageNO);
    }
    @ApiOperation("按编号查询角色信息")
    @ApiImplicitParam(name="id",value = "编号",required = true)
    @RequestMapping("findById")
    @RequiresPermissions("role:*")
    public RoleBean findById(Integer id){
        return roleService.findById(id);
    }
    @ApiOperation(value ="添加角色",notes = "添加角色对象，同时添加角色权限")
    @ApiImplicitParam(name="gradeIdArr",value = "等级编号数组")
    @RequestMapping("add")
    @RequiresPermissions("role:*")
    public String add(RoleBean role,Integer[] gradeIdArr){
        roleService.add(role,gradeIdArr);
        return "ok";
    }
    @ApiOperation(value = "修改角色等级",notes = "按编号修改角色等级")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "角色编号",required = true),
            @ApiImplicitParam(name="gradeIdArr",value = "等级编号数组",required = true)
    })
    @RequestMapping("updateGrades")
    @RequiresPermissions("role:*")
    public String updateGrades(Integer id,Integer[] gradeIdArr){
        roleService.updateGrades(id,gradeIdArr);
        return "ok";
    }
    @ApiOperation(value = "查询所有角色")
    @RequestMapping("findAll")
    @RequiresPermissions("role:*")
    public List<RoleBean> findAll(){
        return roleService.findAll();
    }
    @RequestMapping("del")
    @ApiOperation(value = "按编号删除角色")
    @ApiImplicitParam(name="id",value = "编号",required = true)
    @RequiresPermissions("role:*")
    public String del(Integer id){
        roleService.del(id);
        return "ok";
    }

}
